'''
Created on 2010-12-16

@author: yaron hu
'''

import wx

class RefactorFrame(wx.Frame):
  def __init__(self, parent, id):
    wx.Frame.__init__(self, parent, id, "Refactor Frame", size=(400, 300))
    self.panel = wx.Panel(self, -1)
    self.panel.SetBackgroundColour("White")
    
    # Create Menu Bar
    self.createMenuBar()
    
    # Create Button Bar
    self.createButtonBar(self.panel)
    
    # Create static Text Bar
    

  
  def menuDate(self):
    return (("&File",("&Open", "Open a File", self.OnOpen),
             ("&Quit", "Good bye, boy", self.OnQuit)),
            ("&Edit",("&Copy", "Copy It", self.OnCopy),
             ("C&ut", "Cut It", self.OnCut),
             ("&Paste", "Paste It", self.OnPaste)))
  
  def buttonData(self):
    return (("First", self.OnFirst), ("<< Prev", self.OnPrew),
            ("Next >>", self.OnNext), ("Last", self.OnLast))
  
  def staticTextData(self):
    return (("First Name", (10, 50)), ("Last Name", (10, 80)))
  
  
  def createMenuBar(self):
    menuBar = wx.MenuBar()
    for eachMenuData in self.menuDate():
      menuLabel = eachMenuData[0]
      menuItemData = eachMenuData[1:]
      menuBar.Append(self.buildOneMenu(menuItemData), menuLabel)
    self.SetMenuBar(menuBar)
    
  
  def createButtonBar(self, panel, yPos=0):
    xPos = 0
    for eachLabel, eachHandler in self.buttonData():
      pos = (xPos, yPos)
      btn = self.buildOneButton(panel, eachLabel, eachHandler, pos)
      xPos += btn.GetSize().width
  
  def createStaticText(self, panel):
    for eachLabel, eachPos in self.staticTextData():
      self.createStaticText(panel, eachLabel, eachPos)
    
  
  
  def buildOneMenu(self, menuData):
    menu = wx.Menu()
    for eachLabel, eachStatus, eachHandler in menuData:
      if not eachLabel:
        menu.AppendSeparator()
        continue
      menuItem = menu.Append(-1, eachLabel, eachStatus)
      self.Bind(wx.EVT_MENU, eachHandler, menuItem)
    return menu
  
  def buildOneButton(self, panel,label, handler, pos=(0,0)):
    button = wx.Button(panel, -1, label, pos)
    self.Bind(wx.EVT_BUTTON, handler, button)
    return button
  
  def buildOneStatic(self):
    pass
  
  
  def OnFirst(self, event): pass
  def OnPrew(self, event): pass
  def OnNext(self, event): pass
  def OnLast(self, event): pass
  def OnOpen(self, event): pass
  def OnQuit(self, event):
    self.Close()
  
  def OnCopy(self, event): pass
  def OnCut(self, event): pass
  def OnPaste(self, event): pass
  
  def OnWindowClose(self, event):
    self.Destroy()



if __name__ == '__main__':
  app = wx.PySimpleApp()
  frame = RefactorFrame(None, -1)
  frame.Show()
  app.MainLoop()